<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    input {
      position: sticky;
      top: 0;
      left: 0;
      width: 100%;
      height: 30px;
      min-width: 280px;
      padding: 4px;
    }
  </style>
</head>

<body>
  <p>郑嘉铭创建的</p>
  <div>1111</div>

  <h2>orange-橙子</h2>
  <div>Myinput</div>
  <input class="b" type="text" placeholder="请输入内容">
  <div class="h" style="height: 2000px;"></div>
</body>

</html>
<script>
  let num = 370;
  addEventListener("scroll", function windowScroll() {
    let scrollTop =
      window.pageYOffset ||
      document.documentElement.scrollTop ||
      document.body.scrollTop;
    const inp = document.querySelector(".b");
    if (scrollTop <= 160) {
      num -= 8;
      inp.style.width = `${num}px`;
    } else {
      removeEventListener("scroll", this.windowScroll);
    }
  });
</script>